﻿#include "DataInputStream.h"
#include "lang/Exception.h"
using namespace yzrilyzr_lang;
namespace yzrilyzr_io{
	DataInputStream::DataInputStream(InputStream & in) : FilterInputStream(in), DataInput(){}
	int32_t DataInputStream::read(){
		return input->read();
	}
	u_index DataInputStream::read(yzrilyzr_array::ByteArray & buf, u_index off, u_index len){
		return input->read(buf, off, len);
	}
	void DataInputStream::close(){
		input->close();
	}
	u_index DataInputStream::skipBytes(u_index n){
		u_index total=0;
		u_index cur=0;
		while((total < n) && ((cur=input->skip(n - total)) > 0)){
			total+=cur;
		}
		return total;
	}
	void DataInputStream::readFully(yzrilyzr_array::ByteArray & b, u_index off, u_index len){
		u_index n=0;
		while(n < len){
			u_index count=input->read(b, off + n, len - n);
			if(count < 0)
				throw EOFException();
			n+=count;
		}
	}
}